// const nologin = document.querySelector('.head-user-lists')
// const loginyes = document.querySelector('.loginyes')
// // console.log(nologin);
// // console.log(loginyes);
// const userName = localStorage.getItem('username')
// const passWord = localStorage.getItem('password')
// console.log(userName);
// console.log(passWord);

// testLogin()
// function testLogin() {


//   // 如果没有, 表示曾经没有登录过
//   if (!userName|| !passWord) {
//     // off 盒子显示
//     nologin.classList.add('active')
//     loginyes.classList.remove('active')
//     return
//   }
  


// }



window.onload = function () {
  //点击跳转页面
document.addEventListener('click',(e) =>{
  e = e || window.event
  var target = e.target || e.srcElement
  if (target.nodeName === 'A'){
    window.location.href = './list.html'
  }
  if (target.nodeName === 'LI'){
    window.location.href = './list.html'
  }
  if (target.nodeName === 'IMG'){
    window.location.href = './list.html'
  }
  })
   //渲染函数
   getCarList();
   async function getCarList() {
    const res = await pAjax({
      url: "/vivo?t=1633684329504",
      dataType: "json",
    });
    // console.log(res);
    // console.log(res.data.navigateVos);


    //渲染版图模块二级菜单
    let index = 0;
    res.data.navigateVos.forEach((item) => {
      // console.log(index);
      
      let ul1 = document.createElement("ul");

      ul1.innerHTML = `
    
      <a  class="category-all">
        全部手机
        <span class="arrow">&gt;</span>
      </a>
      <p>${item.firstCategory.name}</p>
     
      `;
      let ol2 = document.createElement("ol");
      $(ol2).addClass('category-sub has-border')

      for (let i = 0; i < item.subCategories.length; i++) {
        ol2.innerHTML += `
      <li>
        <a style="background-image:url(${item.subCategories[i].imgUrl});">${item.subCategories[i].name}</a>
      </li>
        `;
      }
      let ul3 = document.createElement("ul");
      $(ul3).addClass('category-product')
      for (let i = 0; i < item.subCategories.length; i++) {
        ul3.innerHTML += `
        <li>
        <i class="icon-tag">
          <img src="${item.commoditySpus[i].label}" alt="">
        </i>
        <a>
          <img src="${item.commoditySpus[i].imgUrl}" alt="">
          <span>${item.commoditySpus[i].name}</span>
        </a>
      </li>
        `;
      }
      $(".bannermenu").eq(index).children("div").append(ul1);
      $(".bannermenu").eq(index).children("div").append(ol2);
      $(".bannermenu").eq(index).children("div").append(ul3);
      index++;
    });
      //渲染版图二级菜单结束


      //渲染 版图下面第一行
    // console.log(res.data.homeMetaVO.homeFloorList[0].elementList);
    res.data.homeMetaVO.homeFloorList[0].elementList.forEach(item => {
    //  console.log(item);
     let li = document.createElement("li");
     $(li).addClass('box')
        li.innerHTML  = `
           <a>
             <img src="${item.picSrc} "alt="">
           </a>
        `
        $('.fp .box-list').append(li)
    });
     //渲染 版图下面第一行结束

    //渲染热卖专区
    res.data.homeMetaVO.homeFloorList[1].elementList.forEach(item => {
      //  console.log(item);
       let li = document.createElement("li");
       $(li).addClass('box')
          li.innerHTML  = `
          <a>
          <img src="${item.picSrc}"
            alt="">
        </a>
        <div class="prodinfo">
          <p class="name">${item.name}</p>
          <p class="feature">${item.spec}</p>
          <p class="price rmb-symbol">¥${item.salePrice}.00</p>
        </div>
          `
          $('.c_3 .box-list').append(li)
      });

      // 渲染精品手机
      res.data.homeMetaVO.homeFloorList[2].elementList.forEach(item => {
        // console.log(item);
        let li = document.createElement("li");
        $(li).addClass('box')
           li.innerHTML  = `
           <a>
           <img src="${item.picSrc}"
             alt="">
         </a>
         <div class="prodinfo">
           <p class="name">${item.name}</p>
           <p class="feature">${item.spec}</p>
           <p class="price rmb-symbol">¥${item.salePrice}.00</p>
         </div>
           `
           $('.pc_6 .box-list').append(li)
       });
  
       //渲染精品配件
       res.data.homeMetaVO.homeFloorList[3].elementList.forEach(item => {
        // console.log(item);
        let li = document.createElement("li");
        $(li).addClass('box')
           li.innerHTML  = `
           <a>
           <img src="${item.picSrc}"
             alt="">
         </a>
         <div class="prodinfo">
           <p class="name">${item.name}</p>
           <p class="feature">${item.spec}</p>
           <p class="price rmb-symbol">¥${item.salePrice}.00</p>
         </div>
           `
           $('.c_8 .box-list').append(li)
       });
       //渲染精品配件结束
  }
  //渲染页面函数结束



  //版图二级菜单
  const bannerMenu = document.querySelectorAll(".bannermenu");
  const categoryBox = document.querySelectorAll(".category-box");

  for (let i = 0; i < bannerMenu.length; i++) {
    bannerMenu[i].addEventListener("mouseover", function () {
      // console.log(this);
      // console.log(this.children[1]);
      this.children[1].style.display = "block";
    });
    bannerMenu[i].addEventListener("mouseout", function () {
      this.children[1].style.display = "none";
    });
  }
};


//   getCartList_1()
//     async function getCartList_1() {
//         const res = await pAjax({
//             url: '/vivoHot?t=1633940360986',
//             dataType: 'json'
//         })
//         console.log(res);

// }
// function restime() {
